//
//  AppDelegate.swift
//  YPush
//
//  Created by 灵魂码师 on 11/06/2024.
//  Copyright (c) 2024 灵魂码师. All rights reserved.
//

import UIKit
import YPush

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        YPush.initSDK(option: YPushOption(appKey: ""))
        YPush.setAlias(alias: "")
        YPush.setOnOnlineMessageReceive { data in
            
        }
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        YPush.setDeviceToken(deviceToken: deviceToken)
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        YPush.handleRemoteNotification(userInfo: userInfo)
        completionHandler(UIBackgroundFetchResult.newData)
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        YPush.handleRemoteNotification(userInfo: userInfo)
    }
}

